import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn/learn/inherit/Config.dart';
import 'package:flutter_learn/learn/inherit/ConfigUpdater.dart';
import 'package:flutter_learn/learn/inherit/ConfigWidget.dart';

class ConfiguredPage extends StatefulWidget {
  const ConfiguredPage({Key? key, this.child}) : super(key: key);
  final Widget? child;

  @override
  _ConfiguredPageState createState() => _ConfiguredPageState();
}

class _ConfiguredPageState extends State<ConfiguredPage> {
  Config _config = Config(color: Colors.green, fontSize: 16);

  @override
  Widget build(BuildContext context) {
    print("重新构建＝＝＝＞ConfiguredPage");
    return ConfigWidget(
      config: _config,
      child: Column(
        children: [
          ConfigUpdater(
            onColorChanged: (Color? color) {
              /*    setState(() {
                _config = _config.copyWith(color: color);
              });*/
            },
            onFontSizeIncreased: () {
              /*   setState(() {
                _config = _config.copyWith(fontSize: _config.fontSize + 1.0);
              });*/
            },
          ),
          Container(
            child: Builder(
              builder: (context) {
                print("ffffffffffffffffffffffffffff");
                return widget.child!;
              },
            ),
            decoration: BoxDecoration(border: Border.all()),
            padding: EdgeInsets.all(8),
          ),
          ElevatedButton(
            onPressed: () {
              setState(() {});
            },
            child: Text("+"),
          )
        ],
      ),
    );
  }
}
